<template>
  <div class="login-container">
    <div class="login-content">
      <div class="login-left">
        <img src="https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg" alt="登录banner" />
      </div>
      <div class="login-box">
        <div class="login-header">
          <img src="@/assets/logo.svg" alt="logo" class="logo" />
          <div class="login-title">统一认证平台</div>
          <div class="login-subtitle">Welcome to IAM Platform</div>
        </div>
        
        <el-tabs v-model="activeTab" class="login-tabs">
          <el-tab-pane label="账号密码登录" name="account">
            <account-login />
          </el-tab-pane>
          <el-tab-pane label="扫码登录" name="qrcode">
            <qrcode-login />
          </el-tab-pane>
          <el-tab-pane label="验证码登录" name="sms">
            <sms-login />
          </el-tab-pane>
        </el-tabs>
        
        <div class="divider">
          <span>其他登录方式</span>
        </div>
        <div class="third-party-login">
          <div class="login-icons">
            <el-tooltip content="微信登录" placement="top">
              <div class="icon-item" @click="handleThirdLogin('wechat')">
                <el-icon><ChatRound /></el-icon>
              </div>
            </el-tooltip>
            <el-tooltip content="QQ登录" placement="top">
              <div class="icon-item" @click="handleThirdLogin('qq')">
                <el-icon><ChatDotRound /></el-icon>
              </div>
            </el-tooltip>
            <el-tooltip content="Github登录" placement="top">
              <div class="icon-item" @click="handleThirdLogin('github')">
                <el-icon><Position /></el-icon>
              </div>
            </el-tooltip>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>


<script setup>
import { ref } from 'vue'
import AccountLogin from './components/AccountLogin.vue'
import QrcodeLogin from './components/QrcodeLogin.vue'
import SmsLogin from './components/SmsLogin.vue'
import { ChatRound, ChatDotRound, Position } from '@element-plus/icons-vue'

const activeTab = ref('account')

const handleThirdLogin = (type) => {
  const redirectUri = encodeURIComponent(window.location.origin + '/login/callback')
  
  let url = ''
  switch(type) {
    case 'wechat':
      url = `/api/oauth2/wechat/authorize?redirect_uri=${redirectUri}`
      break
    case 'qq':
      url = `/api/oauth2/qq/authorize?redirect_uri=${redirectUri}`
      break
    case 'github':
      url = `/api/oauth2/github/authorize?redirect_uri=${redirectUri}`
      break
  }
  
  window.open(url, '_self')
}
</script>

<style scoped>
.login-container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #1890ff 0%, #1d39c4 100%);
}

.login-content {
  display: flex;
  width: 1000px;
  height: 600px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.login-left {
  flex: 1;
  background: #f5f7fa;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-left img {
  width: 80%;
  height: auto;
}

.login-box {
  width: 400px;
  padding: 40px;
  position: relative;
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.logo {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
}

.login-title {
  font-size: 24px;
  color: #1890ff;
  font-weight: bold;
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 14px;
  color: #999;
}

:deep(.el-tabs__nav) {
  width: 100%;
  display: flex;
}

:deep(.el-tabs__item) {
  flex: 1;
  text-align: center;
}

:deep(.el-tabs__content) {
  overflow: visible;
  margin-bottom: 0;
}

:deep(.el-form) {
  margin-bottom: 0;
}

:deep(.el-form-item:last-child) {
  margin-bottom: 0;
}

.divider {
  display: flex;
  align-items: center;
  color: #999;
  font-size: 14px;
  margin: 16px 0 12px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #eee;
  margin: 0 16px;
}

.third-party-login {
  text-align: center;
  padding: 0;
}

.login-icons {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 8px;
}

.icon-item {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
  background: #f5f7fa;
}

.icon-item:hover {
  transform: translateY(-2px);
  background: #e6f7ff;
}

.icon-item .el-icon {
  font-size: 20px;
  color: #666;
}

.icon-item:nth-child(1):hover .el-icon {
  color: #07c160;  /* 微信绿 */
}

.icon-item:nth-child(2):hover .el-icon {
  color: #12b7f5;  /* QQ蓝 */
}

.icon-item:nth-child(3):hover .el-icon {
  color: #24292e;  /* Github黑 */
}
</style> 